﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Collections.ObjectModel;
using System.Windows;
using Test_01;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

namespace WordsOfLove
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
   
    public sealed partial class NewsPage : Page
    {
        public NewsPage()
        {
            this.InitializeComponent();
        }
        private void NewsLists_ItemClick(object sender, ItemClickEventArgs e)
        {
            var seleNews = (NewsList)e.ClickedItem;
            this.Frame.Navigate(typeof(NewsContent),seleNews );
        }
        // Class defintion should be provided within the namespace being used, outside of any other classes.
        // These two declarations belong outside of the main page class.
        private ObservableCollection<NewsList> _newslists = new ObservableCollection<NewsList>();

        public ObservableCollection<NewsList> NewsLists
        {
            get { return this._newslists; }
        }

        // This method should be defined within your main page class.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Instead of hard coded items, the data could be pulled 
            // asynchronously from a database or the internet.
            /*Contacts.Add(new Contact("John", "Doe", "ABC Printers"));
            Contacts.Add(new Contact("Jane", "Doe", "XYZ Refridgerators"));
            Contacts.Add(new Contact("Santa", "Claus", "North Pole Toy Factory Inc.")); */
            Crawler crawler = new Crawler();
            List<string> titlelist = crawler.GetTitle("world", "america");
            List<string> imadlist = crawler.GetPic("world", "america");
            List<string> newsadlist = crawler.GetAddress("world", "america");
            for (int i=0;i <imadlist.Count;i++)
            {
                NewsLists.Add(new NewsList(i,titlelist[i], imadlist[i],newsadlist[i]));
            }
        }
    }
    
    public class NewsList
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string ContentAd { get; set; }
        public string ImageAddress { get; set; }
        public NewsList(int id, string title,string imageAddress,string contentad)
        {
            this.Title = title;
            this.ImageAddress = imageAddress;
            this.ContentAd = contentad;
            this.Id = id;
        }
    }

}
